//
//  AdvertisingModel.m
//  HTP
//
//  Created by admin on 15/11/18.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "AdvertisingModel.h"

@implementation AdvertisingModel
-(BOOL)saveBean{
    AdvertisingData * advertData = [AdvertisingData findFirstByAttribute:@"adId" withValue:self.adId];
    if (advertData == nil) {
        advertData = [AdvertisingData createEntity];
    }
    advertData.adEndTime = self.adEndTime;
    advertData.adHtmlUrl = self.adHtmlUrl;
    advertData.adId = self.adId;
    advertData.adImageUrl = self.adImageUrl;
    advertData.adStartTime = self.adStartTime;
    advertData.adStatus = self.adStatus;
    advertData.adType = self.adType;
    return [XLCoreDataManager save];
}
+(id)initWithAdvertisingData:(AdvertisingData *)advertising{
    AdvertisingModel * advertM = [[AdvertisingModel alloc] init];
    advertM.adEndTime = advertising.adEndTime;
    advertM.adHtmlUrl = advertising.adHtmlUrl;
    advertM.adId = advertising.adId;
    advertM.adImageUrl = advertising.adImageUrl;
    advertM.adStartTime = advertising.adStartTime;
    advertM.adStatus = advertising.adStatus;
    advertM.adType = advertising.adType;
    return advertM;
}
+(NSArray *)creatAdvertisings:(NSArray *)advertisingArray{
    NSMutableArray *dataArray = [NSMutableArray array];
    [advertisingArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        AdvertisingData *advertisingData = (AdvertisingData *)obj;
        [dataArray addObject:[AdvertisingModel initWithAdvertisingData:advertisingData]];
    }];
    return dataArray;
}
@end
